package com.lanqiao.gxnushop.util;

import java.util.HashSet;
import java.util.Random;
import java.util.Set;

public class AccountUtil {
    private static final int ACCOUNT_LENGTH = 11;
    private static final int MAX_ATTEMPTS = 1000000; // 防止无限循环
    private static final Set<String> generatedAccounts = new HashSet<String>();
    private static final Random random = new Random();

    private static String generateUniqueAccount() {
        int attempts = 0;
        while (attempts < MAX_ATTEMPTS) {
            String account = generateRandomAccount();
            if (generatedAccounts.add(account)) {
                return account;
            }
            attempts++;
        }
        throw new RuntimeException("Failed to generate a unique account after " + MAX_ATTEMPTS + " attempts");
    }

    private static String generateRandomAccount() {
        StringBuilder account = new StringBuilder(ACCOUNT_LENGTH);
        for (int i = 0; i < ACCOUNT_LENGTH; i++) {
            account.append(random.nextInt(10)); // 生成0-9之间的随机数字
        }
        return account.toString();
    }
    //获取1000个不重复的11位账号
    public static String getAccount(){
        // 生成不重复的11位账号示例`
        String account = generateUniqueAccount();
        return account;
    }
}
